from google.appengine.ext import webapp
from app_facade import AppFacade


class GenericHandler(webapp.RequestHandler):
    def __init__(self):
        self._facade = AppFacade.get_instance()
        if self._startup_notification:
            self._facade.send_notification(self._startup_notification, self)


class HomeHandler(GenericHandler):
    def __init__(self):
        self._startup_notification = AppFacade.HOME_STARTUP
        super(HomeHandler, self).__init__()

    def get(self):
        self._facade.send_notification(AppFacade.GET_HOME)


class NewMpHandler(GenericHandler):
    def __init__(self):
        self._startup_notification = AppFacade.NEW_MP_STARTUP
        super(NewMpHandler, self).__init__()

    def get(self):
        self._facade.send_notification(AppFacade.VIEW_MP_NEW)

    def post(self):
        pdict = {}
        vlist = ['cname', 'ename', 'street', 'suite', 'city', 'state',
                 'zip', 'country', 'phone', 'fax', 'web']

        for i in range(len(vlist)):
            value = self.request.get(vlist[i])
            if len(value) > 0:
                pdict[vlist[i]] = value

        self._facade.send_notification(AppFacade.ADD_MP, pdict)
